home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.GraphicsEnvironment;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.ClipboardOwner;
- import java.awt.datatransfer.DataFlavor;
- import java.awt.datatransfer.Transferable;
- import java.awt.dnd.DropTargetListener;
- import java.awt.event.InputEvent;
- import java.awt.event.MouseEvent;
- import java.beans.BeanInfo;
- import java.beans.IntrospectionException;
- import java.beans.Introspector;
- import java.beans.PropertyDescriptor;
- import java.io.Serializable;
- import java.lang.reflect.Method;
- import sun.awt.AppContext;
- import sun.reflect.misc.MethodUtil;
-
- public class TransferHandler implements Serializable {
- public static final int NONE = 0;
- public static final int COPY = 1;
- public static final int MOVE = 2;
- public static final int COPY_OR_MOVE = 3;
- public static final int LINK = 1073741824;
- private String propertyName;
- private static SwingDragGestureRecognizer recognizer = null;
- static final Action cutAction = new TransferAction("cut");
- static final Action copyAction = new TransferAction("copy");
- static final Action pasteAction = new TransferAction("paste");
-
- public static Action getCutAction() {
- return cutAction;
- }
-
- public static Action getCopyAction() {
- return copyAction;
- }
-
- public static Action getPasteAction() {
- return pasteAction;
- }
-
- public TransferHandler(String var1) {
- this.propertyName = var1;
- }
-
- protected TransferHandler() {
- this((String)null);
- }
-
- public void exportAsDrag(JComponent var1, InputEvent var2, int var3) {
- int var4 = this.getSourceActions(var1);
- if (!(var2 instanceof MouseEvent) || var3 != 1 && var3 != 2 && var3 != 1073741824 || (var4 & var3) == 0) {
- var3 = 0;
- }
-
- if (var3 != 0 && !GraphicsEnvironment.isHeadless()) {
- if (recognizer == null) {
- recognizer = new SwingDragGestureRecognizer(new DragHandler((1)null));
- }
-
- recognizer.gestured(var1, (MouseEvent)var2, var4, var3);
- } else {
- this.exportDone(var1, (Transferable)null, 0);
- }
-
- }
-
- public void exportToClipboard(JComponent var1, Clipboard var2, int var3) throws IllegalStateException {
- if ((var3 == 1 || var3 == 2) && (this.getSourceActions(var1) & var3) != 0) {
- Transferable var4 = this.createTransferable(var1);
- if (var4 != null) {
- try {
- var2.setContents(var4, (ClipboardOwner)null);
- this.exportDone(var1, var4, var3);
- return;
- } catch (IllegalStateException var6) {
- this.exportDone(var1, var4, 0);
- throw var6;
- }
- }
- }
-
- this.exportDone(var1, (Transferable)null, 0);
- }
-
- public boolean importData(TransferSupport var1) {
- return var1.getComponent() instanceof JComponent ? this.importData((JComponent)var1.getComponent(), var1.getTransferable()) : false;
- }
-
- public boolean importData(JComponent var1, Transferable var2) {
- PropertyDescriptor var3 = this.getPropertyDescriptor(var1);
- if (var3 != null) {
- Method var4 = var3.getWriteMethod();
- if (var4 == null) {
- return false;
- }
-
- Class[] var5 = var4.getParameterTypes();
- if (var5.length != 1) {
- return false;
- }
-
- DataFlavor var6 = this.getPropertyDataFlavor(var5[0], var2.getTransferDataFlavors());
- if (var6 != null) {
- try {
- Object var7 = var2.getTransferData(var6);
- Object[] var8 = new Object[]{var7};
- MethodUtil.invoke(var4, var1, var8);
- return true;
- } catch (Exception var9) {
- System.err.println("Invocation failed");
- }
- }
- }
-
- return false;
- }
-
- public boolean canImport(TransferSupport var1) {
- return var1.getComponent() instanceof JComponent ? this.canImport((JComponent)var1.getComponent(), var1.getDataFlavors()) : false;
- }
-
- public boolean canImport(JComponent var1, DataFlavor[] var2) {
- PropertyDescriptor var3 = this.getPropertyDescriptor(var1);
- if (var3 != null) {
- Method var4 = var3.getWriteMethod();
- if (var4 == null) {
- return false;
- }
-
- Class[] var5 = var4.getParameterTypes();
- if (var5.length != 1) {
- return false;
- }
-
- DataFlavor var6 = this.getPropertyDataFlavor(var5[0], var2);
- if (var6 != null) {
- return true;
- }
- }
-
- return false;
- }
-
- public int getSourceActions(JComponent var1) {
- PropertyDescriptor var2 = this.getPropertyDescriptor(var1);
- return var2 != null ? 1 : 0;
- }
-
- public Icon getVisualRepresentation(Transferable var1) {
- return null;
- }
-
- protected Transferable createTransferable(JComponent var1) {
- PropertyDescriptor var2 = this.getPropertyDescriptor(var1);
- return var2 != null ? new PropertyTransferable(var2, var1) : null;
- }
-
- protected void exportDone(JComponent var1, Transferable var2, int var3) {
- }
-
- private PropertyDescriptor getPropertyDescriptor(JComponent var1) {
- if (this.propertyName == null) {
- return null;
- } else {
- Class var2 = var1.getClass();
-
- BeanInfo var3;
- try {
- var3 = Introspector.getBeanInfo(var2);
- } catch (IntrospectionException var8) {
- return null;
- }
-
- PropertyDescriptor[] var4 = var3.getPropertyDescriptors();
-
- for(int var5 = 0; var5 < var4.length; ++var5) {
- if (this.propertyName.equals(var4[var5].getName())) {
- Method var6 = var4[var5].getReadMethod();
- if (var6 != null) {
- Class[] var7 = var6.getParameterTypes();
- if (var7 == null || var7.length == 0) {
- return var4[var5];
- }
- }
- }
- }
-
- return null;
- }
- }
-
- private DataFlavor getPropertyDataFlavor(Class<?> var1, DataFlavor[] var2) {
- for(int var3 = 0; var3 < var2.length; ++var3) {
- DataFlavor var4 = var2[var3];
- if ("application".equals(var4.getPrimaryType()) && "x-java-jvm-local-objectref".equals(var4.getSubType()) && var1.isAssignableFrom(var4.getRepresentationClass())) {
- return var4;
- }
- }
-
- return null;
- }
-
- private static DropTargetListener getDropTargetListener() {
- synchronized(DropHandler.class) {
- DropHandler var1 = (DropHandler)AppContext.getAppContext().get(DropHandler.class);
- if (var1 == null) {
- var1 = new DropHandler((1)null);
- AppContext.getAppContext().put(DropHandler.class, var1);
- }
-
- return var1;
- }
- }
-
- // $FF: synthetic method
- static DropTargetListener access$200() {
- return getDropTargetListener();
- }
- }
-